package rs.networx.entity;

import static javax.persistence.CascadeType.ALL;
import static javax.persistence.FetchType.LAZY;
import static javax.persistence.GenerationType.IDENTITY;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name="persons")
public class Person implements java.io.Serializable {

	private static final long serialVersionUID = 943686373L;

	@Id
	@GeneratedValue(strategy=IDENTITY)	
	@Column(name="person_id", unique=true, nullable=false)
	private Integer id;

	@Column(name="firstname", unique=false, nullable=false)
	private String firstName;

	@Column(name="lastname", unique=false, nullable=false)
	private String lastName;

	@Column(name="dob", unique=false, nullable=false)
	private java.util.Date dob;

	@Column(name="sex", unique=false, nullable=false)
	private String sex;

	@Column(name="email", unique=false, nullable=false)
	private String email;

	@Column(name="password", unique=false, nullable=false)
	private String password;

	@Column(name="place", unique=false, nullable=false)
	private String place;

	@Column(name="website", unique=false, nullable=false)
	private String webSite;

	@Column(name="education", unique=false, nullable=false)
	private String education;

	@Column(name="employment", unique=false, nullable=false)
	private String employment;

	@Column(name="picture", unique=false, nullable=true)
	private String picture;

	@Column(name="activated", unique=false, nullable=false)
	private Boolean activated;

	@Transient
	private Boolean loggedIn;

	@OneToMany(cascade={ALL}, fetch=LAZY, mappedBy="commetator")
	private Set<Comment> comments = new HashSet<Comment>();	

	@ManyToMany
	@JoinColumn(name="friends")
	private Set<Person> friends = new HashSet<Person>();

	@OneToMany(cascade={ALL}, fetch=LAZY, mappedBy="requestFrom")
	private Set<FriendRequest> hasRequested = new HashSet<FriendRequest>();

	@OneToMany(cascade={ALL}, fetch=LAZY, mappedBy="requestTo")
	private Set<FriendRequest> isRequested = new HashSet<FriendRequest>();

	@OneToMany(cascade={ALL}, fetch=LAZY, mappedBy="owner")
	private Set<Post> ownedPosts = new HashSet<Post>();

	@OneToMany(cascade={ALL}, fetch=LAZY, mappedBy="poster")
	private Set<Post> postedPosts = new HashSet<Post>();

	@OneToMany(cascade={ALL}, fetch=LAZY, mappedBy="owner")
	private Set<Nottification> nottifications = new HashSet<Nottification>();

	public Person() {
	}
	public Person(String firstName, String lastName, Date dob, String sex, String email, String password, String place, String webSite,
			String education, String employment, String picture) {	
		super();
		this.firstName = firstName;
		this.lastName = lastName;
		this.dob = dob;
		this.sex = sex;
		this.email = email;
		this.password = password;
		this.place = place;
		this.webSite = webSite;
		this.education = education;
		this.employment = employment;
		this.picture = picture;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public java.util.Date getDob() {
		return dob;
	}

	public void setDob(java.util.Date dob) {
		this.dob = dob;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPlace() {
		return place;
	}

	public void setPlace(String place) {
		this.place = place;
	}

	public String getWebSite() {
		return webSite;
	}

	public void setWebSite(String webSite) {
		this.webSite = webSite;
	}

	public String getEducation() {
		return education;
	}

	public void setEducation(String education) {
		this.education = education;
	}

	public String getEmployment() {
		return employment;
	}

	public void setEmployment(String employment) {
		this.employment = employment;
	}

	public String getPicture() {
		return picture;
	}

	public void setPicture(String picture) {
		this.picture = picture;
	}

	public Boolean getActivated() {
		return activated;
	}

	public void setActivated(Boolean activated) {
		this.activated = activated;
	}

	public Boolean getLoggedIn() {
		return loggedIn;
	}

	public void setLoggedIn(Boolean loggedIn) {
		this.loggedIn = loggedIn;
	}

	public Set<Comment> getComments() {
		return comments;
	}

	public void setComments(Set<Comment> comments) {
		this.comments = comments;
	}

	public Set<Person> getFriends() {
		return friends;
	}

	public void setFriends(Set<Person> friends) {
		this.friends = friends;
	}

	public Set<FriendRequest> getHasRequested() {
		return hasRequested;
	}

	public void setHasRequested(Set<FriendRequest> hasRequested) {
		this.hasRequested = hasRequested;
	}

	public Set<FriendRequest> getIsRequested() {
		return isRequested;
	}

	public void setIsRequested(Set<FriendRequest> isRequested) {
		this.isRequested = isRequested;
	}

	public Set<Post> getOwnedPosts() {
		return ownedPosts;
	}

	public void setOwnedPosts(Set<Post> ownedPosts) {
		this.ownedPosts = ownedPosts;
	}

	public Set<Post> getPostedPosts() {
		return postedPosts;
	}

	public void setPostedPosts(Set<Post> postedPosts) {
		this.postedPosts = postedPosts;
	}

	public Set<Nottification> getNottifications() {
		return nottifications;
	}

	public void setNottifications(Set<Nottification> nottifications) {
		this.nottifications = nottifications;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public Integer getId() {
		return id;
	}
	
	@Override
	public boolean equals(Object obj) {
		Person comparePerson = (Person) obj;
		System.out.println("                                                        Usao sam ovde!!!");
		return id == comparePerson.getId();
	}

	public String toString() {
		return "Person" + " id=" + id + " firstName=" + firstName
		+ " lastName=" + lastName + " dob=" + dob + " sex=" + sex
		+ " email=" + email + " password=" + password + " place="
		+ place + " webSite=" + webSite + " education=" + education
		+ " employment=" + employment + " picture=" + picture
		+ " activated=" + activated + " loggedIn=" + loggedIn;
	}
}